<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>居中显示</title>
    <style>
        .f {
            width: 300px;
            height: 100px;
            background-color: lightseagreen;

            /* 设置绝对定位，会破坏margin:auto的效果 */
            position: absolute;
            left: 50%;
            top: 50%;
            margin-top: -50px;
            margin-left: -15px;
        }

        .s {
            width: 30px;
            height: 30px;
            background-color: lightcoral;
            border-radius: 50%;
            /* 右顶角 */
            position: absolute;
            top: -5px;
            right: -5px;

            /* 文本居中 */
            text-align: center;
            /* 文本数值居中 */
            line-height: 30px;
        }
    </style>
</head>

<body>
    <div class="f">
        <div class="s">x</div>
    </div>
</body>

</html>